/* eslint-disable array-callback-return,no-undef */
import React, { Component } from 'react';
import { Layout, Tabs, Form, Spin, Row, Col } from 'antd';
import styles from '../../index.less';
import Toolbar from '../Common/ToolBar/ToolBarNew';
import * as commonFunc from '../Common/commonFunc';
import CommonBase from '../Common/CommonBase';
import CommonJurisdictionEvent from '../Common/CommonJurisdictionEvent';
import * as commonBusiness from '../Common/commonBusiness'; /* 单据业务功能 */
import StaticEditTable from '../Common/CommonTable'; /* 可编辑表格 */
import StaticEditTree from '../Common/Tree/StaticTree';

const { Header, Content } = Layout;
const { TabPane } = Tabs;

class SystemPermissionComponentInfo extends Component {
  constructor(props) {
    super(props);
    this.state = {
    };
    this.form = {}; /*   表单对象   */
  }
  render() {
    const { pageLoading } = this.props;
    return (
      <div>
        <Spin spinning={pageLoading}>
          <div>
            <SystemPermissionComponent
              {...this.props}
              {...this.state}
            />
          </div>
        </Spin>
      </div>
    );
  }
}
const SystemPermissionComponent = Form.create({
  mapPropsToFields(props) {
    const { masterData } = props;
    const obj = commonFunc.mapPropsToFields(masterData, Form);
    return obj;
  },
})((props) => {
  // console.log('props', props);
  const {
    form, onReturnForm,
  } = props;

  const groupProps = {
    ...commonBusiness.getTableTypes('group', props),
    tableProps: { rowSelection: null },
    // rowSelectionType: 'radio',
    enabled: false,
  };

  const userProps = {
    ...commonBusiness.getTableTypes('user', props),
    tableProps: { rowSelection: null },
    enabled: false,
  };

  const userGroupProps = {
    ...commonBusiness.getTableTypes('userGroup', props),
    tableProps: { rowSelection: null, rowKey: 'sUsersId' },
    enabled: false,
  };

  const groupUserProps = {
    ...commonBusiness.getTableTypes('groupUser', props),
    tableProps: { rowSelection: null, rowKey: 'sGroupsId' },
    enabled: false,
  };

  const treeProps = {
    ...commonBusiness.getTreeTypes('tree', props),
  };

  const checkedNodesProps = {
    ...commonBusiness.getTableTypes('checkedNodes', props),
    tableProps: { rowSelection: null },
    enabled: false,
  };

  /*   回带表单   */
  onReturnForm(form);
  return (
    <Form>
      <Layout>
        <Header className={styles.header}>
          <Toolbar {...props} />
        </Header>
        <Layout className={styles.clayout}>
          <Content className={styles.content}>
            <Layout className={styles.clayoutJur}>
              <Row type="flex" justify="space-between">
                <Col span={10} style={{ marginTop: 10 }}>
                  <Row>
                    <Col span={12} key="{groupProps.name}Col">
                      <StaticEditTable {...groupProps} />
                    </Col>
                    <Col span={12} key="{userProps.name}Col">
                      <StaticEditTable {...userProps} />
                    </Col>
                  </Row>
                  <Row>
                    <Col span={12} key="2">
                      <StaticEditTable {...userGroupProps} />
                    </Col>
                    <Col span={12} key="4">
                      <StaticEditTable {...groupUserProps} />
                    </Col>
                  </Row>
                </Col>
                <Col span={14}>
                  <div id="slaveTabs">
                    <Tabs className={styles.slaveTabs}>
                      <TabPane tab="权限内容" key="5" >
                        <StaticEditTree {...treeProps} />
                      </TabPane>
                      <TabPane tab="已有权限" key="6" >
                        <StaticEditTable {...checkedNodesProps} />
                      </TabPane>
                    </Tabs>
                  </div>
                </Col>
              </Row>
            </Layout>
          </Content>
        </Layout>
      </Layout>
    </Form>
  );
});

export default CommonBase(CommonJurisdictionEvent(SystemPermissionComponentInfo));

